package com.example.javaeekeshe.service.impl;

import com.example.javaeekeshe.service.IRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisServiceImpl implements IRedisService {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public boolean setValue(String key, String value) {
        try {
            redisTemplate.opsForValue().set(key,value,60, TimeUnit.SECONDS);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public String getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
